<template>
  <div id="newSongs">
    <div class="split">
      <div class="dot"></div>
      <span>最新音乐</span>
    </div>
    <div class="newsong-box">
      <!-- 歌曲 -->
      <div class="item" v-for="item in newSongs" :key="item.id" @click="playMusic($event,item.id)">
        <div class="cover">
          <img v-lazy="item.picUrl" alt="" />
        </div>
        <div class="music-info">
          <div class="music-name">{{ item.name }}</div>
          <div class="music-artists">
            {{ item.song.artists | filterArtists }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "NewSongs",
  computed: {
    ...mapState({
      newSongs: (state) => state.home.newSongs,
    }),
  },
  mounted() {
    this.$store.dispatch("newSongs");
  },
  methods:{
    // 播放选中的音乐
    playMusic(e, id){
      this.$store.dispatch('appendOne', id)
    }
  }
};
</script>

<style lang='less'>
#newSongs {
  margin-top: 30px;
  .split {
    display: flex;
    align-items: center;
    .dot {
      width: 5px;
      height: 22px;
      background: var(--themeColor1);
      display: inline-block;
      margin-right: 10px;
    }
    font-size: 20px;
    font-weight: bold;
    padding-left: 5px;
  }
  .newsong-box {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .item:hover {
      background: #eee;
    }
    .item {
      cursor: pointer;
      border-radius: 5px;
      margin-top: 20px;
      width: 29%;
      padding: 0 1% 0 0;
      display: flex;
      .cover {
        flex: 2;
        img {
          width: 100%;
          border-radius: 5px;
        }
      }
      .music-info {
        flex: 8;
        margin-left: 10px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 5px 0;
        div {
          font-size: 14px;
          display: -webkit-box; /**对象作为伸缩盒子模型展示**/
          -webkit-box-orient: vertical; /**设置或检索伸缩盒子对象的子元素的排列方式**/
          -webkit-line-clamp: 1; /**显示的行数**/
          overflow: hidden; /**隐藏超出的内容**/
        }
        .music-name {
          font-size: 14px;
        }
        .music-artists {
          font-size: 12px;
          color: #999;
        }
      }
    }
  }
}
</style>